package com.warmlight.voicepacket;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
import com.warmlight.voicepacket.adapter.PostDetailsAdapter;
import com.warmlight.voicepacket.base.BaseActivity;
import com.warmlight.voicepacket.data.PostDetalData;
import com.warmlight.voicepacket.data.ReplyListBean;
import com.warmlight.voicepacket.http.HttpClient;
import com.warmlight.voicepacket.http.HttpConfig;
import com.warmlight.voicepacket.http.ResponseData;
import com.warmlight.voicepacket.ui.communitylm.widget.ReplyBar;
import com.warmlight.voicepacket.ui.communitylm.widget.ReplyBarBase;
import com.warmlight.voicepacket.ui.user.LoginRegistActivity;
import com.warmlight.voicepacket.utils.JSONUtils;
import com.warmlight.voicepacket.utils.SPUtils;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;

/**
 * 星球详情
 */
public class PostDetailsActivity extends BaseActivity {

    private String type;
    private Map<String, String> item;

    public static void startPostDetailsActivity(Context context, String itemId){
        Intent intent=new Intent(context,PostDetailsActivity.class);
        intent.putExtra("itemId",itemId);
        context.startActivity(intent);
    }

    /**
     * 这个是从消息点击跳入时使用，根据type 类型进行不同的跳转
     * @param mContext
     * @param finalPost_res_id
     */
    /**
     * * 消息类型：0评论我的帖子
     * 1评论我的评论
     * 2在我的帖子中回复了别人
     * 3赞了我的帖子
     * 4赞了我的评论
     * 5其它
     * 6系统可点击消息
     * 7对我的音频点赞
     */
    public static void startPostDetailsWithCommentDetailActivity(Context mContext,
                                                                 String type,
                                                                 String finalPost_res_id,
                                                                 Map<String,String> item) {
        Intent intent=new Intent(mContext,PostDetailsActivity.class);
        intent.putExtra("type",type);
        intent.putExtra("itemId",finalPost_res_id);
        intent.putExtra("msg", (Serializable) item);
        mContext.startActivity(intent);
    }
    private  String itemId;
    private RecyclerView comment_rl;
    private PostDetailsAdapter adapter = null;
    private List<PostDetalData.ReplyListBean> list = new ArrayList<>();
    private int page = 1;
    private  View ll_tabbarf ,ll_tabbar;
    private TextView tv_header_titlenamef;
    private LinearLayout ll_backf;
    private ImageView iv_backf;
    private ReplyBar replyBar;
    private  RefreshLayout refreshLayout;
    private int postion=0;
    private PostDetalData.PostInfoBean post_info;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setSystemBarTransparent();
        setContentView(R.layout.activity_postdetail);
//        onImmersionStatusBar();
        //当FitsSystemWindows设置 true 时，会在屏幕最上方预留出状态栏高度的 padding
//        StatusBarUtil.setRootViewFitsSystemWindows(this,true);
//        //设置状态栏透明
//        StatusBarUtil.setTranslucentStatus(this);
//        //一般的手机的状态栏文字和图标都是白色的, 可如果你的应用也是纯白色的, 或导致状态栏文字看不清
//        //所以如果你是这种情况,请使用以下代码, 设置状态使用深色文字图标风格, 否则你可以选择性注释掉这个if内容
//        StatusBarUtil.setStatusBarDarkTheme(this, false);
//        //如果不支持设置深色风格 为了兼容总不能让状态栏白白的看不清, 于是设置一个状态栏颜色为半透明,
//        //这样半透明+白=灰, 状态栏的文字能看得清
//        StatusBarUtil.setStatusBarColor(this,getResources().getColor(R.color.bar_grey));
////        }
//        //当FitsSystemWindows设置 true 时，会在屏幕最上方预留出状态栏高度的 padding
//        StatusBarUtil.setRootViewFitsSystemWindows(this,false);
//        StatusBarUtil.setTranslucentStatus(this);
        Bundle bundle = getIntent().getExtras();
        if (bundle != null){
            itemId = bundle.getString("itemId");
            /**
             *  post_id = getIntent().getStringExtra("post_id");
             reply_id = getIntent().getStringExtra("reply_id");
             uid = getIntent().getStringExtra("uid");
             */
            if (bundle.containsKey("type")){
                type = bundle.getString("type");
//                String post_id = bundle.getString("itemId");
                item = (Map<String, String>) bundle.getSerializable("msg");
//                msgType(type, item);
            }
        }

        initView();
        initReplyBar();
        initData();

    }

    private void msgType(){
        if (!TextUtils.isEmpty(type) && item != null) {
            String id = item.get("id");//消息id
            String uid = item.get("uid");//接收者UID
            String content = item.get("content");//消息内容
            String jump_page = item.get("jump_page");//消息跳转页面：1帖子2评论3发布的音频
            String pic = item.get("pic");//对应的图片，空为无图片，否则为图片地址
            String related_id = item.get("related_id");//跳转到对应的id
            String send_uid = item.get("send_uid");//发送者的uid
            String add_time = item.get("add_time");//添加时间戳
            String read_time = item.get("read_time");//读取时间
            String update_time = item.get("update_time");//更新时间
            String author = item.get("author");//发送者的用户信息
            String datetime = item.get("datetime");//发送时间，前端显示用
            String a_uid = "";
            String a_nickname = "";
            String a_avator = "";
            String a_sex = "";
            String a_sign = "";
            //对我评论的人的信息
            if (!TextUtils.isEmpty(author)) {
                ArrayList<Map<String, String>> authors = JSONUtils.getListMapByJson(author);
                if (authors.size() > 0) {
                    Map<String, String> map = authors.get(0);
                    a_uid = map.get("uid");
                    a_nickname = map.get("nickname");
                    a_avator = map.get("avator");
                    a_sex = map.get("sex");
                    a_sign = map.get("sign");
                }
            }

            /**
             * "comment_res":{
             "id":"88314",
             "pics":[

             ],
             "content":"急急急",
             "status":"2",
             "post_id":"2409",
             "reply_id":"0"
             }
             */

            //帖子的评论
            final String comment_res = item.get("comment_res");
            String comment_res_id = "";
            String coment_res_pics = "";
            String coment_res_content = "";
            String coment_res_post_id = "";
            if (!TextUtils.isEmpty(comment_res)) {
                ArrayList<Map<String, String>> comment_res_list = JSONUtils.getListMapByJson(comment_res);
                if (comment_res_list.size() > 0) {
                    Map<String, String> map = comment_res_list.get(0);
                    comment_res_id = map.get("id");
                    coment_res_pics = map.get("pics");
                    coment_res_content = map.get("content");
                    coment_res_post_id = map.get("post_id");
                }
            }


            //别人回复你的信息
            final String reply_res = item.get("reply_res");
            String reply_res_content = "";//别人回复我的信息
            String reply_res_id = "";//回复的回复的id
//            String reply_id = "";//帖子评论的id
            if (!TextUtils.isEmpty(reply_res)) {
                ArrayList<Map<String, String>> reply_ress = JSONUtils.getListMapByJson(reply_res);
                if (reply_ress.size() > 0) {
                    Map<String, String> map = reply_ress.get(0);
                    reply_res_id = map.get("id");
                    reply_res_content = map.get("content");
                    String status = map.get("status");
                    String post_id = map.get("post_id");
                    String reply_id = map.get("reply_id");
                }
            }
            //当前帖子的信息，展示右侧的图片或者文字
//        String post_res = item.get("post_res");
//        String post_res_content = "";//右侧文字 没有图片就展示文字
//        String pic_right = "";//右侧图片
//        String post_res_id = "";//帖子的id
//        if (!TextUtils.isEmpty(post_res)){
//            ArrayList<Map<String, String>> post_res_list = JSONUtils.getListMapByJson(post_res);
//            if (post_res_list.size()>0){
//                Map<String, String> map = post_res_list.get(0);
//                post_res_id = map.get("id");
//                post_res_content = map.get("content");
//                String category = map.get("category");//1 图文 2 视频
//                if (TextUtils.equals("1",category)){
//                    String post_res_pics = map.get("pics");
//                    ArrayList<Map<String, String>> pics = JSONUtils.getListMapByJson(post_res_pics);
//                    if (pics.size()>0){
//                        Map<String, String> map1 = pics.get(0);
//                        pic_right = map1.get("");
//                    }
//                }else{
//                    String post_res_video = map.get("video");
//                    ArrayList<Map<String, String>> videos = JSONUtils.getListMapByJson(post_res_video);
//                    if (videos.size()>0){
//                        String cover_img = videos.get(0).get("cover_img");
//                        ArrayList<Map<String, String>> cover_imgs = JSONUtils.getListMapByJson(cover_img);
//                        if (cover_imgs.size()>0){
//                            Map<String, String> map1 = cover_imgs.get(0);
//                            pic_right = map1.get("u");
//                        }
//                    }
//                }
//            }
//        }


            if (TextUtils.equals("0", type)) {
                PostDetalData.ReplyListBean msgReplyListBean = new PostDetalData.ReplyListBean();
                msgReplyListBean.setId(comment_res_id);
                msgReplyListBean.setPost_id(coment_res_post_id);
                msgReplyListBean.setContent(coment_res_content);
                msgReplyListBean.setLike_num(0);
                msgReplyListBean.setIs_like(0);
                msgReplyListBean.setReply_num("0");
                msgReplyListBean.setDate(datetime);
                PostDetalData.ReplyListBean.UserBeanX userBeanX = new PostDetalData.ReplyListBean.UserBeanX();
                userBeanX.setSex(a_sex);
                userBeanX.setAvator(a_avator);
                userBeanX.setNickname(a_nickname);
                userBeanX.setUid(a_uid);
                msgReplyListBean.setUser(userBeanX);

                List<PostDetalData.ReplyListBean.PicsBean> picsBeans = new ArrayList<>();
                if (!TextUtils.isEmpty(coment_res_pics)) {
                    ArrayList<Map<String, String>> picss = JSONUtils.getListMapByJson(coment_res_pics);
                    for (int i = 0; i < picss.size(); i++) {
                        Map<String, String> o = picss.get(i);
                        String w = o.get("w");
                        String h = o.get("h");
                        String u = o.get("u");
                        String is_gif = o.get("is_gif");

                        PostDetalData.ReplyListBean.PicsBean picsBean = new PostDetalData.ReplyListBean.PicsBean();
                        picsBean.setW(w);
                        picsBean.setH(h);
                        picsBean.setU(u);
                        picsBean.setIs_gif(is_gif);
                        picsBeans.add(picsBean);
                    }
                }

                msgReplyListBean.setPics(picsBeans);
                if (list.get(1).getId()!= msgReplyListBean.getId()){
                    for (int i=0;i<list.size();i++){
                        if (list.get(i).getId()==msgReplyListBean.getId()){
                            list.remove(i);
                            break;
                        }
                    }
                    list.add(1,msgReplyListBean);
                    adapter.notifyDataSetChanged();
                }
            }else if (TextUtils.equals("1",type)){
                Intent intent = new Intent(this,CommentDetailAcitivity.class);
                intent.putExtra("post_id",coment_res_post_id);
                intent.putExtra("reply_id",comment_res_id);
                intent.putExtra("uid",uid);
                intent.putExtra("type",type);
                intent.putExtra("msg", (Serializable) item);
                startActivity(intent);
            }




            type = "";
            item = null;
        }
    }


//    public int getStatusBarId() {
//        return R.id.status_padding;
//    }
    private void setSystemBarTransparent() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    // LOLLIPOP解决方案
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            getWindow().setStatusBarColor(Color.BLACK);
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    // KITKAT解决方案
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
}
    /**
     * 沉浸式状态栏 5.1以上
     * */
//    public void onImmersionStatusBar(){
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
//            Window window = getWindow();
//            int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
//                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
//            View decorView = getWindow().getDecorView();
//            decorView.setSystemUiVisibility(option);
//            window.setStatusBarColor(Color.TRANSPARENT);
//            if(getStatusBarId() != 0){
//                View view = findViewById(getStatusBarId());
//                view.getLayoutParams().height = StatusBarUtil.getStatusBarHeight(this);
//            }
//        }
//    }


    private void initReplyBar(){
        final ReplyBarBase replyBarBase = findViewById(R.id.reply_bar_base);
        replyBar = findViewById(R.id.reply_bar);

        replyBarBase.setOnReplyBarBaseClickListener(new ReplyBarBase.ReplyBarBaseClickListener() {
            @Override
            public void clickText() {
                replyBar.showReplyBar(true,true);
            }

            @Override
            public void clickImg() {
                replyBar.showReplyBar(true,false);
                replyBar.addPhoto();
            }
        });
        comment_rl.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                replyBar.setOnTouch();
                return false;
            }
        });

        /**
         * {"uid":"162830","content":"你好","pics":[],"post_id":342,"reply_id":0,"to_uid":0,"status":2,"add_time":1536757336,"id":0}
         *
         * /**
         * id : 75437
         * post_id : 342
         * content : 不扎的慌么
         * like_num : 0
         * is_like : false
         * is_god : 0
         * reply_num : 0
         * date : 27天前
         * pics : []
         * user : {"uid":"124332","nickname":"爱吾不死","avator":"https://nuanguang-img.oss-cn-shanghai.aliyuncs.com/post/avator/a8877460bb8cad0f717f19771bcde6b8_1535810314.jpg","sex":"0"}
         *private String id;
         private String post_id;
         private String content;
         private int like_num;
         private int is_like;
         private String is_god;
         private String reply_num;
         private String date;
         private UserBeanX user;
         private List<PicsBean> pics;
         */
//        replyBar.setOnReplyBarLisener(new ReplyBar.ReplyBarReplySuccessLisener() {
//            @Override
//            public void success(String data) {
//                try {
//                    PostDetalData.ReplyListBean replyListBean = new PostDetalData.ReplyListBean();
//
//                    JSONObject jsonObject = new JSONObject(data);
//
//                    String id = jsonObject.optString("id");
//                    String post_id = jsonObject.optString("post_id");
//                    String content = jsonObject.optString("content");
//                    int like_num = jsonObject.optInt("like_num");
//                    int is_like = jsonObject.optInt("is_like");
//                    String is_god = jsonObject.optString("is_god");
//                    String reply_num = jsonObject.optString("reply_num");
//                    String date = jsonObject.optString("date");
//
//                    JSONObject user = jsonObject.optJSONObject("user");
//                    String uid = user.optString("uid");
//                    String nickname = user.optString("nickname");
//                    String avator = user.optString("avator");
//                    String sex = user.optString("sex");
//
//                    PostDetalData.ReplyListBean.UserBeanX userBeanX = new PostDetalData.ReplyListBean.UserBeanX();
//                    userBeanX.setUid(uid);
//                    userBeanX.setNickname(nickname);
//                    userBeanX.setAvator(avator);
//                    userBeanX.setSex(sex);
//
//                    JSONArray jsonArray = jsonObject.optJSONArray("pics");
//                    List<PostDetalData.ReplyListBean.PicsBean> pics = new ArrayList<>();
//                    for (int i=0;i<jsonArray.length();i++){
//                        JSONObject o = (JSONObject) jsonArray.get(i);
//                        String w = o.optString("w");
//                        String h = o.optString("h");
//                        String u = o.optString("u");
//                        String is_gif = o.optString("is_gif");
//
//                        PostDetalData.ReplyListBean.PicsBean picsBean = new PostDetalData.ReplyListBean.PicsBean();
//                        picsBean.setW(w);
//                        picsBean.setH(h);
//                        picsBean.setU(u);
//                        picsBean.setIs_gif(is_gif);
//                        pics.add(picsBean);
//                    }
//
//                    replyListBean.setId(id);
//                    replyListBean.setPost_id(post_id);
//                    replyListBean.setContent(content);
//                    replyListBean.setLike_num(like_num);
//                    replyListBean.setIs_like(is_like);
//                    replyListBean.setIs_god(is_god);
//                    replyListBean.setReply_num(reply_num);
//                    replyListBean.setDate(date);
//                    replyListBean.setUser(userBeanX);
//                    replyListBean.setPics(pics);
//
//                    list.add(1,replyListBean);
//                    if (adapter != null){
//                        adapter.notifyDataSetChanged();
//                    }
//                } catch (JSONException e) {
//                    e.printStackTrace();
//                }
//
//            }
//        });
    }

    /**
     * 设置回复框的参数
     * @param post_info
     */
    private void setReplyBar(PostDetalData.PostInfoBean post_info){
        String id = post_info.getId();
        if (replyBar != null){
            replyBar.setReplyBar(0,id,"0",post_info.getUser().getUid());
        }
    }


    private void initView() {
         ll_tabbarf = findViewById(R.id.ll_tabbarf);
         ll_tabbar = findViewById(R.id.ll_tabbar);
        comment_rl = findViewById(R.id.comment_rl);
        tv_header_titlenamef=findViewById(R.id.tv_header_titlenamef);
        ll_backf=findViewById(R.id.ll_backf);
        iv_backf=findViewById(R.id.iv_backf);
        Log.e("initView: 11", "1111111");
         refreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
        refreshLayout.setEnableRefresh(false);//启用刷新
        comment_rl.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));

        comment_rl.setItemAnimator(new DefaultItemAnimator());

        comment_rl.setOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);

            }

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                LinearLayoutManager l = (LinearLayoutManager) recyclerView.getLayoutManager();
                //获取RecyclerView当前顶部显示的第一个条目对应的索引
                int position = l.findFirstVisibleItemPosition();
                //根据索引来获取对应的itemView
                View firstVisiableChildView = l.findViewByPosition(position);
                //获取当前显示条目的高度
                int itemHeight = firstVisiableChildView.getHeight();
                //获取当前Recyclerview 偏移量
                int flag = (position) * itemHeight - firstVisiableChildView.getTop();
                //TODO  320  需要动态设置
                int height=320;
                if (flag > height) {
                    flag = height;
                    iv_backf.setImageDrawable(getResources().getDrawable(R.drawable.icon_back));
                }else {
                    iv_backf.setImageDrawable(getResources().getDrawable(R.drawable.back));
                }
                if (flag<=100){
                    flag=0;
                }else {
                    flag=flag-100;
                }
                tv_header_titlenamef.setTextColor(Color.argb(Math.round(flag * 255 * 1f / (height-100)), 0, 0, 0));
                ll_tabbarf.setBackgroundColor(Color.argb(Math.round(flag * 255 * 1f / (height-100)), 255, 255, 255));
                Log.e("onScrolled: ", flag + "");
            }
        });

        refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
            @Override
            public void onLoadMore(RefreshLayout refreshlayout) {
                page++;
                refreshlayout.finishLoadMore(2000/*,false*/);//传入false表示加载失败
                initData();
            }
        });
    }

    private void initData() {
        String POSTDEL = HttpConfig.POSTDEL;
        TreeMap<String, String> treeMap = new TreeMap<>();
        treeMap.put("post_id", itemId);//帖子id
        treeMap.put("page", String.valueOf(page));
        treeMap.put("pagesize", "15");
        HttpClient.getInstance().postRxAndroidAES(POSTDEL, treeMap)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<ResponseData>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(ResponseData responseData) {

                        if (TextUtils.equals("200", responseData.getCode())) {
                            final PostDetalData postDetalData = new Gson().fromJson(responseData.getData(), PostDetalData.class);
//                            Log.e("onNext: ", data.getReply_list().size() + "");
                            if (adapter == null) {//这里是加了个空的头部
                                PostDetalData.ReplyListBean bean = new PostDetalData.ReplyListBean();
                                list.add(bean);

                            }
                            post_info = postDetalData.getPost_info();
                            setReplyBar(post_info);
                            list.addAll(postDetalData.getReply_list());
                            if (postDetalData.getReply_has_more()==0){
                                refreshLayout.setEnableLoadMore(false);
                            }
                            if (adapter == null) {

                                if (post_info.getCategory().equals("1")){
                                    ll_tabbarf.setVisibility(View.GONE);
                                }else {
                                    ll_tabbar.setVisibility(View.GONE);
                                }
                                adapter = new PostDetailsAdapter(list,post_info ,getThis());
                                adapter.setOnZanDataListener(new PostDetailsAdapter.OnZanDataListener() {
                                    @Override
                                    public void zanData(String id, int Postion,boolean iszan) {
                                        initOnZanHttp(id,Postion,iszan);
                                    }
                                });
                                adapter.setOnClickListener(new PostDetailsAdapter.OnClickListener() {
                                    @Override
                                    public void onClick(int position) {
                                        postion=position;
                                    }
                                });
                                comment_rl.setAdapter(adapter);
                            } else {
                                adapter.notifyDataSetChanged();
                            }
                            msgType();

                        } else {
                            showToast(responseData.getMsg());
                        }
                    }

                    @Override
                    public void onError(Throwable e) {
                        showToast("数据请求失败");
                    }

                    @Override
                    public void onComplete() {

                    }
                });

        EventBus.getDefault().register(this);
    }
    private void initOnZanHttp(String id, final int Position, final boolean iszan){
        if (!SPUtils.isLogined()){
            Intent intent = new Intent(getContext(), LoginRegistActivity.class);
            startActivity(intent);
            return;
        }
        String POSTDEL = HttpConfig.MEMBERLIKE;
        TreeMap<String, String> treeMap = new TreeMap<>();
        treeMap.put("id", id);//id
        treeMap.put("status",!iszan?"1":"2" );
        treeMap.put("type", Position==0?"1":"2");//todo 位置是1的时候是帖子  不是评论
        HttpClient.getInstance().postRxAndroidAES(POSTDEL, treeMap)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<ResponseData>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(ResponseData responseData) {

                        if (TextUtils.equals("200", responseData.getCode())) {
                            String body = responseData.getBody();
                            try {
                                JSONObject object =new JSONObject(body);
                                String data =object.getString("data");
                                if (data.equals("成功")){
                                    if (postion!=0) {
                                        int like_num = list.get(Position).getLike_num();
                                        if (iszan) {
                                            list.get(Position).setIs_like(0);
                                            list.get(Position).setLike_num(like_num - 1);
                                        } else {
                                            list.get(Position).setIs_like(1);
                                            list.get(Position).setLike_num(like_num + 1);
                                        }
                                    }else {
                                        int like_num = post_info.getLike_num();
                                        if (iszan) {
                                            post_info.setIs_like(0);
                                            post_info.setLike_num(like_num - 1);
                                        } else {
                                            post_info.setIs_like(1);
                                            post_info.setLike_num(like_num + 1);
                                        }

                                    }

                                    adapter.notifyDataSetChanged();
                                }

                            } catch (JSONException e) {
                                e.printStackTrace();
                            }

                        } else {
                            showToast(responseData.getMsg());
                        }
                    }

                    @Override
                    public void onError(Throwable e) {
                        showToast("数据请求失败");
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (replyBar != null){
            replyBar.onActivityResult(requestCode,resultCode,data);
        }
    }

    @Override
    public void onBackPressed() {
        if (isTaskRoot()){
            finish();
            Intent intent = new Intent(this,MainActivity.class);
            startActivity(intent);
        }else {
            super.onBackPressed();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void XXX(ReplyListBean.ListBean listBean){
//        list.get(postion).setIs_like(listBean.isIs_like());
//        list.get(postion).setLike_num(listBean.getLike_num());
//        adapter.notifyDataSetChanged();
    }
}
